import { Options } from '../entity/Options';
import { cp } from 'fs/promises';
import { log } from './log';
import { resolve } from 'node:path';
import { getZipName } from './parameter';

export async function copySourceCode(options: Options) {
  let relativePath = options.platform !== 'osx'
      ? 'package.nw'
      : 'nwjs.app/Contents/Resources/app.nw';
  let zipName = getZipName(options);
  let srcPath = resolve(options.srcDir);
  let targetPath = resolve(`${options.cacheDir}/${zipName}/${relativePath}`);
  log.debug(`即将复制源代码，源代码位置: '${srcPath}', 目标位置: '${targetPath}'`);
  await cp(srcPath, targetPath, {recursive: true});
  log.debug('复制成功');
}
